//An attempt at a DNA molecular structuring system,
//which chemicals, diseases, and dna splicing can change your genetic make-up


int HUMAN_SPECIES	1,129
int RAT_SPECIES		130,255


var/total_blocks = 4
var/list/disease_types = list(
"epilepsy"	= 1,
"cough"		= 2,
"nervous"	= 4,
)

mob/verb/play_with_dna()
	var/datum/dna/D = new()
	src.dna = D
	src.dna.create_dna(src)
	src.dna.check_dna(src)

	var/dat = "DNA Blocks:<br>"
	for(var/v in src.dna.blocks)
		dat += "[src.dna.blocks[v]] , "


	src<<browse(dat, "window=dna;size=550x550")

datum
	dna
		var/list/blocks = list()
		var/disease		= 0			//genetic diseases
		var/real_name
		var/dna

		proc
			create_dna(mob/who)
				if(!who || !ismob(who)) return


				blocks = list()
				real_name = who.ckey


				var/gender_block
				if(who.gender == "male")
					gender_block = num2hex(rand(1,128))
				else
					gender_block = num2hex(rand(129,255))



				blocks["gender"] = gender_block

				if(istype(who, /mob/human))
					blocks["species"] = num2hex(rand(HUMAN_SPECIES))
				else if(istype(who, /mob/rat))
					blocks["species"] = num2hex(rand(RAT_SPECIES))


				//disease blocks
				//give them half a chance of being healthy by multiplying len by itself
				var/disease_range = ( 255 / (disease_types.len * 2) )
				var/r = rand(1,disease_types.len*2)
				var/dat
				if(r <= disease_types.len)
					debug("r is [r]")
					dat = r * disease_range - rand(1,disease_range-1)

				else
					debug("r not in list [r]")
					dat = r * disease_range
				debug("dat is [dat]")
				blocks["fake1"] = num2hex(rand(1,255))
				blocks["fake2"] = num2hex(rand(1,255))

				dna = ""
				for(var/v in blocks)
					dna += "[blocks[v]]"

			check_dna(mob/who)
				if(!who || !ismob(who)) return

				if(!blocks || (blocks.len < total_blocks))
					src.create_dna(who)
					return
				if(blockon(blocks["fake1"]))
					world<<"\red you feel nervous."

				//blocks["species"] = num2hex(144)
				if((hex2num(blocks["species"]) > 129) && istype(who,/mob/human))
					world<<"rat transforming"
					var/mob/rat/rat = new ()
					rat.loc = locate(who.x,who.y,who.z)

					who.client.mob = rat






proc
	blockon(hx)
		var/r = (255 / (disease_types.len * 2))
		var/hex = hex2num(hx)

		//if hex is less than the first three blocks, you are healthy. Giving you a 1/2 chance.
		if(hex <= r*3)
			return 0
		else
			return 1